﻿@{
    Layout = null;
}
<!DOCTYPE html>
<html>
<head>
    <title>StudentLogin</title>
    <script src="../../Scripts/jquery-1.5.1.min.js" type="text/javascript"></script>
    <script src="../../Scripts/jquery.simplemodal.1.4.1.min.js" type="text/javascript"></script>
    <link href="../../Content/Styles/LoginStyle.css" rel="stylesheet" type="text/css" />
    <link href="../../Content/Site.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript">
        $(document).ready(function () {
            $.ajaxSetup({ cache: false });
            InitValidateCode();
        })

        //注册验证码
        function InitValidateCode() {
            //首次加载
            $("#validateCode").attr("src", "/Common/GetValidateCode?time=" + (new Date()).getTime());
            //单击验证码事件
            $("#validateCode").bind("click", function () {
                this.src = "/Common/GetValidateCode?time=" + (new Date()).getTime();
                $.get("/Common/GetCurrentValidateCode", function (data) {
                    $("#validateCode").val(data);
                });
            });
        };

        function CheckPage() {
            if ($("#txtLoginCode").val() == "") {
                alert("请填写用户名！");
                return false;
            }
            if ($("#txtPassword").val() == "") {
                alert("请填写密码！");
                return false;
            }
            if ($("#txtValidateCode").val() == "") {
                alert("请填写验证码！");
                return false;
            }
            Login();
        };

        function Login() {
            $.ajax({
                type: "GET",
                url: "/Test/StudentTest",
                data: { loginCode: function () { return $("#txtLoginCode").val() }, password: function () { return $("#txtPassword").val() }, validateCode: function () { return $("#txtValidateCode").val() } },
                beforeSend: function () { $.modal("<img src='@Url.Content("~/Content/Images/loading.gif")' alt=''></img>");},
                success: function (msg) {
                    if (msg == "success") {
                        window.location = "/Test/PrepareTest";
                    }
                    else {
                        alert(msg);
                    }
                },
                complete: function () {
                    $("#txtPassword").val("");
                    InitValidateCode();
                    $.modal.close();
                }
            });
        }
    </script>
</head>
<body>
    <center>
        <div style="margin-top: 20%">
            <table>
                <tr>
                    <td>
                        请输入准考证号：
                    </td>
                    <td>
                        <input type="text" id="txtLoginCode" />
                    </td>
                </tr>
                <tr>
                    <td>
                        请输入密码：
                    </td>
                    <td>
                        <input type="password" id="txtPassword" />
                    </td>
                </tr>
                <tr>
                    <td>
                        请输入验证码
                    </td>
                    <td>
                        <div style="float: left;">
                            <input type="text" id="txtValidateCode" style=" width:85px;" />
                        </div>
                        <div style="float: left; margin-left: 7px;">
                            <img id="validateCode" src="/Common/GetCheckCode" alt="" />
                        </div>
                    </td>
                </tr>
                <tr>
                    <td>
                    </td>
                    <td>
                        <input type="button" value="登录" onclick="CheckPage()" />
                    </td>
                </tr>
            </table>
        </div>
    </center>
</body>
</html>
